home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 41.1 KB | 1,122 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { UMacAppUtilities.p }
- { Copyright © 1984-1990 Apple Computer, Inc. All rights reserved. }
- {
- This unit implements a set of simple type declarations and utility
- routines.
- }
-
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := FALSE}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT UMacAppUtilities;
-
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED __UMacAppUtilities__}
- {$SETC __UMacAppUtilities__ := FALSE}
- {$ENDC}
-
- {$IFC NOT __UMacAppUtilities__}
- {$SETC __UMacAppUtilities__ := TRUE}
-
- { • Directive settings to EXPORT }
- {$IFC qDebug}
- {$W-}
- {$ELSEC}
- {$W+}
- {$ENDC}
-
- {$IFC qUnInit}
- {$Init+}
- {$ELSEC}
- {$Init-}
- {$ENDC}
-
- {$IFC qRangeCheck}
- {$R+}
- {$OV+}
- {$ELSEC}
- {$R-}
- {$OV-}
- {$ENDC}
-
- {$IFC qTrace}
- {$D++}
- {$N+}
- {$ELSEC}
- {$IFC qNames}
- {$D+}
- {$N+}
- {$ELSEC}
- {$D-}
- {$N-}
- {$ENDC}
- {$ENDC}
-
- { • Auto-Include the requirements for this unit's interface. }
- {$SETC UMacAppUtilitiesIncludes := UsingIncludes}
- {$SETC UsingIncludes := TRUE}
- {$I+}
- {$IFC UNDEFINED UsingTextEdit} {$I TextEdit.p} {$ENDC}
- {$IFC UNDEFINED UsingFiles} {$I Files.p} {$ENDC}
- {$IFC UNDEFINED UsingTraps} {$I Traps.p} {$ENDC}
- {$IFC UNDEFINED UsingScrap} {$I Scrap.p} {$ENDC}
- {$IFC UNDEFINED __ULoMem__} {$I ULoMem.p} {$ENDC}
- {$SETC UsingIncludes := UMacAppUtilitiesIncludes}
-
- CONST
- { In the NON-debug case these are set to false and the code they condition will not be
- compiled }
- {$IFC NOT qDebug}
- gPreCondition = FALSE; { true to do pre-condition processing }
- gPostCondition = FALSE; { true to do post-condition processing }
- {$ENDC}
-
- { set constants from the standard compiletime variables.
- These constants may be used in expressions such that if the expression statically evaluates
- to false then the compiler will omit conditioned code.
-
- if NOT qNeedsColorQD THEN
- mumble;
-
- }
- {[f-]}
- { If for some reason these don't come in from MABuild set them to the highest common form
- -NoDebug -System6
- }
- {$IFC UNDEFINED qHasForward} { Compiler Has FORWARD and EXTERNAL capabilities }
- {$SETC qHasForward := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qDebug}
- {$SETC qDebug := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qDebugTheDebugger}
- {$SETC qDebugTheDebugger := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qInspector}
- {$SETC qInspector := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qMacApp}
- {$SETC qMacApp := TRUE}
- {$EndC}
-
- {$IFC UNDEFINED qNames}
- {$SETC qNames := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsColorQD}
- {$SETC qNeedsColorQD := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsFPU}
- {$SETC qNeedsFPU := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsHierarchicalMenus}
- {$SETC qNeedsHierarchicalMenus := TRUE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsMC68020}
- {$SETC qNeedsMC68020 := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsMC68030}
- {$SETC qNeedsMC68030 := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsROM128K}
- {$SETC qNeedsROM128K := TRUE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsScriptManager}
- {$SETC qNeedsScriptManager := TRUE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsStyleTextEdit}
- {$SETC qNeedsStyleTextEdit := TRUE}
- {$EndC}
-
- {$IFC UNDEFINED qNeedsWaitNextEvent}
- {$SETC qNeedsWaitNextEvent := TRUE}
- {$EndC}
-
- {$IFC UNDEFINED qPerform}
- {$SETC qPerform := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qRangeCheck}
- {$SETC qRangeCheck := FALSE}
- {$EndC}
-
- {$IFC UNDEFINED qTemplateViews}
- {$SETC qTemplateViews := TRUE}
- {$EndC}
-
- {$IFC UNDEFINED qTrace}
- {$SETC qTrace := FALSE}
- {$EndC}
-
- { Flag that indicates that the user wants to play around with the new, UNSUPPORTED
- stuff that we on the MacApp team are fiddling with.
-
- WARNING, Setting this flag true voids your MacApp warranty. It is used to condition
- features that are experimental and UNSUPPORTED. Features enabled with this flag
- may or may not be included in future versions of MacApp and are here for informational
- purposes only.
-
- 'Nuff said. }
-
- {$IFC UNDEFINED qExperimentalAndUnsupported}
- {$SETC qExperimentalAndUnsupported := FALSE}
- {$EndC}
-
-
-
- {$IFC UNDEFINED __cplusplus} { in C++ the compile variables can be used
- in expressions }
- {$IFC qDebug} qDebug = TRUE;
- {$ElseC} qDebug = FALSE; {$EndC}
- { If qDebug then this flag is TRUE else FALSE. }
-
- {$IFC qDebugTheDebugger} qDebugTheDebugger = TRUE;
- {$ElseC} qDebugTheDebugger = FALSE; {$EndC}
- { If qDebugTheDebugger then this flag is TRUE else FALSE. }
-
- {$IFC qInspector} qInspector = TRUE;
- {$ElseC} qInspector = FALSE; {$EndC}
- { If qInspector then this flag is TRUE else FALSE. }
-
- {$IFC qMacApp} qMacApp = TRUE;
- {$ElseC} qMacApp = FALSE; {$EndC}
- { If qMacApp then this flag is TRUE else FALSE. }
-
- {$IFC qNames} qNames = TRUE;
- {$ElseC} qNames = FALSE; {$EndC}
- { If qNames then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsColorQD} qNeedsColorQD = TRUE;
- {$ElseC} qNeedsColorQD = FALSE; {$EndC}
- { If qNeedsColorQD then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsFPU} qNeedsFPU = TRUE;
- {$ElseC} qNeedsFPU = FALSE; {$EndC}
- { If qNeedsFPU then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsHierarchicalMenus} qNeedsHierarchicalMenus = TRUE;
- {$ElseC} qNeedsHierarchicalMenus = FALSE; {$EndC}
- { If qNeedsHierarchicalMenus then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsMC68020} qNeedsMC68020 = TRUE;
- {$ElseC} qNeedsMC68020 = FALSE; {$EndC}
- { If qNeedsMC68020 then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsMC68030} qNeedsMC68030 = TRUE;
- {$ElseC} qNeedsMC68030 = FALSE; {$EndC}
- { If qNeedsMC68030 then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsROM128K} qNeedsROM128K = TRUE;
- {$ElseC} qNeedsROM128K = FALSE; {$EndC}
- { If qNeedsROM128K then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsScriptManager} qNeedsScriptManager = TRUE;
- {$ElseC} qNeedsScriptManager = FALSE; {$EndC}
- { If qNeedsScriptManager then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsStyleTextEdit} qNeedsStyleTextEdit = TRUE;
- {$ElseC} qNeedsStyleTextEdit = FALSE; {$EndC}
- { If qNeedsStyleTextEdit then this flag is TRUE else FALSE. }
-
- {$IFC qNeedsWaitNextEvent} qNeedsWaitNextEvent = TRUE;
- {$ElseC} qNeedsWaitNextEvent = FALSE; {$EndC}
- { If qNeedsWaitNextEvent then this flag is TRUE else FALSE. }
-
- {$IFC qPerform} qPerform = TRUE;
- {$ElseC} qPerform = FALSE; {$EndC}
- { If qPerform then this flag is TRUE else FALSE. }
-
- {$IFC qRangeCheck} qRangeCheck = TRUE;
- {$ElseC} qRangeCheck = FALSE; {$EndC}
- { If qRangeCheck then this flag is TRUE else FALSE. }
-
- {$IFC qTemplateViews} qTemplateViews = TRUE;
- {$ElseC} qTemplateViews = FALSE; {$EndC}
- { If qTemplateViews then this flag is TRUE else FALSE. }
-
- {$IFC qTrace} qTrace = TRUE;
- {$ElseC} qTrace = FALSE; {$EndC}
- { If qTrace then this flag is TRUE else FALSE. }
-
- {$IFC qExperimentalAndUnsupported}qExperimentalAndUnsupported = TRUE;
- {$ElseC} qExperimentalAndUnsupported = FALSE;{$EndC}
- { If qExperimentalAndUnsupported then this flag is TRUE else FALSE. }
-
- {$EndC}
- {[f+]}
-
- { ASCII Character Constants }
- chBackspace = CHR(8); { ASCII code for Backspace character }
- chClear = CHR(27); { ASCII code for Clear key (aka ESC) }
- chDown = CHR(31); { ASCII code for down arrow }
- chEnd = CHR(4); { ASCII code for the End key }
- chEnter = CHR(3); { ASCII code for Enter character }
- chEscape = CHR(27); { ASCII code for Escape (aka Clear) key }
- chFunction = CHR(16); { ASCII code for any function key }
- chFwdDelete = CHR($7F); { ASCII code for forward delete }
- chHelp = CHR(5); { ASCII code for Help key }
- chHome = CHR(1); { ASCII code for the Home key }
- chLeft = CHR(28); { ASCII code for left arrow }
- chPageDown = CHR(12); { ASCII code for Page Down key }
- chPageUp = CHR(11); { ASCII code for Page Up key }
- chReturn = CHR(13); { ASCII code for Return character }
- chRight = CHR(29); { ASCII code for right arrow }
- chSpace = CHR(32); { ASCII code for Space character }
- chTab = CHR(9); { ASCII code for Tab character }
- chUp = CHR(30); { ASCII code for up arrow }
-
- { Virtual Key Code Constants }
- kClearVirtualCode = 71; { Clear key virtual code }
- kEscapeVirtualCode = 53; { Escape key virtual code }
- kF10VirtualCode = 109; { F10 virtual key code }
- kF11VirtualCode = 103; { F11 virtual key code }
- kF12VirtualCode = 111; { F12 virtual key code }
- kF13VirtualCode = 105; { F13 virtual key code }
- kF14VirtualCode = 107; { F14 virtual key code }
- kF15VirtualCode = 113; { F15 virtual key code }
- kF1VirtualCode = 122; { F1 virtual key code }
- kF2VirtualCode = 120; { F2 virtual key code }
- kF3VirtualCode = 99; { F3 virtual key code }
- kF4VirtualCode = 118; { F4 virtual key code }
- kF5VirtualCode = 96; { F5 virtual key code }
- kF6VirtualCode = 97; { F6 virtual key code }
- kF7VirtualCode = 98; { F7 virtual key code }
- kF8VirtualCode = 100; { F8 virtual key code }
- kF9VirtualCode = 101; { F9 virtual key code }
- kFwdDelVirtualCode = 117; { Forward Delete virtual code }
-
- kSysFontName = ''; { GetFontNum converts this to zero. }
- kApplFontName = 'A'; { GetFontNum converts this to one. }
-
- kWordAlign = TRUE; { Constant for OffsetPtr }
- kDontAlign = FALSE; { Constant for OffsetPtr }
-
- kHexDigits = '0123456789ABCDEF'; { Digits in base 16 }
-
- kNoFileRefnum = - (MaxInt - 1); { an invalid file refnum; used to indicate
- an unopened file (actually interpreted by
- HFS as a volume number. If you have this
- many volumes you are sick indeed! }
- kNoStaticLink = - 1; { Pascal functions and procedures can take
- "procedure" parameters which are like C++
- function pointers with the additional
- capabilitly to access upscope variables.
- This is particularly convenient for "call
- back" type procedures because they are
- executed in their original scope. Well
- kids, C++ has no equivalent structure, so
- all of the interfaces that call for a
- "procedure" parameter have been translated
- to a function pointer and a static link
- (upscope variable accessor) in the C++
- headers. The static link can be used to
- pass any useful context information
- around, see the C++ examples. HOWEVER,
- when a static link is not used or
- required; C++ users must insert a non-NIL
- placeholder. The receiving code is in
- pascal and includes special detection of
- the case where NIL is passed for static
- link. When NIL is passed in, >>> NO <<<
- static link will be passed to the
- "procedure" parameter when it is called!
- You can imagine the ensuing heartache for
- well meaning C++ users as their stack gets
- tromped. The answer, my friends is to have
- C++ users pass kNoStaticLink when they
- don't wish to use the static link. }
-
- { Field types for the Fields methods. These are understood by StdFieldToString.
- Negative values are reserved for MacApp.
- }
- bBoolean = - 1;
- bByte = - 2;
- bChar = - 3;
- bClass = - 4;
- bCmdNumber = - 5;
- bCntlAdornment = - 6;
- bControlHandle = - 7;
- bDouble = - 8; { SANE Double }
- bExtended = - 9; { SANE Extended }
- bFixed = - 10;
- bFontName = - 11;
- bGrafPtr = - 12;
- bHandle = - 13;
- bHexInteger = - 14;
- bHexLongInt = - 15;
- bHighByte = - 16;
- bHLState = - 17;
- bIDType = - 18;
- bInteger = - 19;
- bLongInt = - 20;
- bLowByte = - 21;
- bObject = - 22;
- bOSType = - 23;
- bPattern = - 24;
- bPoint = - 25;
- bPointer = - 26;
- bReal = - 27; { Pascal Real }
- bRect = - 28;
- bResType = - 29;
- bRGBColor = - 30;
- bRgnHandle = - 31;
- bSingle = - 32; { SANE Single }
- bSizeDeterminer = - 33;
- bString = - 34;
- bStringHandle = - 35;
- bStyle = - 36;
- bTEHandle = - 37;
- bTitle = - 38;
- bVCoordinate = - 39;
- bVPoint = - 40;
- bVHSelect = - 41;
- bVRect = - 42;
- bWindowPtr = - 43;
-
- {$IFC FALSE} { !!! can't fieldtostring for multiline
- structures yet (2.0)}
- bTextStyle = - 44;
- bConfigRec = - 45;
- bScrapStuff = - 46;
- {$EndC}
-
- kMANameSize = 63; { Maximum size string supported for an
- MAName }
-
- kAutoWrap = TRUE; { Want to AutoWrap (for MATextBox)}
- kNoAutoWrap = NOT kAutoWrap; { Don't want to AutoWrap (for MATextBox)}
- kEraseFirst = TRUE; { Want to erase first (for MATextBox)}
- kNoEraseFirst = NOT kEraseFirst; { Don't want to erase first (for MATextBox)}
- kSpaceForCaret = TRUE; { Want to leave space for an insertion caret
- (for MATextBox)}
- kNoSpaceForCaret = NOT kSpaceForCaret; { Don't want to leave space for an insertion
- caret (for MATextBox)}
- teJustSystem = teJustLeft; { teJustLeft really means use the system
- justification set by the installed script.
- in Arabic and Hebrew systems this is typically
- right justification (but user changeable).
- using a constant with a better name like
- teJustSystem helps to make this issue more
- visible to the developer. If LEFT
- justification is REQUIRED there is of course,
- teForceLeft. }
-
-
- TYPE
- { Some handy types }
- { MacApp used to indicate the pointer datatype by prepending the type name with a "P"
- and a handle datatype by prepending the type name with a "H". In order to be more
- compatible with the standards used in the toolbox interfaces we will now indicate pointer
- datatypes by appending "Ptr" to the typename and handle datatypes by appending "Handle" to
- the typename. The old style names are left in for compatibility in Release 2.0 }
-
- IntegerPtr = ^INTEGER; { Preferred }
- IntegerHandle = ^IntegerPtr; { Preferred }
-
- LongIntPtr = ^LONGINT; { Preferred }
- LongIntHandle = ^LongIntPtr; { Preferred }
-
- BooleanPtr = ^BOOLEAN; { Preferred }
- BooleanHandle = ^BooleanPtr; { Preferred }
-
- SignedBytePtr = ^SignedByte; { Preferred }
- SignedByteHandle = ^SignedBytePtr; { Preferred }
-
- PInteger = IntegerPtr; { Left in for compatibility (2.0) }
- HInteger = IntegerHandle; { Left in for compatibility (2.0) }
- PLongInt = LongIntPtr; { Left in for compatibility (2.0) }
- HLongInt = LongIntHandle; { Left in for compatibility (2.0) }
- PBoolean = BooleanPtr; { Left in for compatibility (2.0) }
- PByte = SignedBytePtr; { Left in for compatibility (2.0) }
-
- String8 = STRING[8];
-
- MAName = STRING[kMANameSize]; { A Name in MacApp®. ClassNames,
- MethodNames, IVar Names, ProcNames, etc.
- ??? Should we punt on stringlength and
- only define pointers to these strings? }
- MANamePtr = ^MAName; { Preferred }
- MANameHandle = ^MANamePtr; { Preferred }
- PMAName = MANamePtr; { Left in for compatibility (2.0) }
- HMAName = MANameHandle; { Left in for compatibility (2.0) }
-
- IDType = ResType; { MacApp uses four byte "signatures" in
- several places. They are a handy way to
- have a partially human readable quantity
- that only takes up a long. }
-
- AdornPieces = (adnLineTop, { Draw a line at the top of the extent }
- adnLineLeft, { Draw a line on the left side of the extent
- }
- adnLineBottom, { Draw a line on the bottom side of the
- extent }
- adnLineRight, { Draw a line on the right side of the
- extent }
- adnDummy, { Place filler… }
- adnOval, { Do a FrameOval using the extent }
- adnRRect, { Do a (16,16) FrameRoundRect using the
- extent }
- adnShadow); { Draw drop shadows against framed
- selections }
- CntlAdornment = SET OF AdornPieces;
-
- VCoordinate = LONGINT; { VCoordinates are 32 bits as compared to QD
- Coordinates which are 16 bits }
-
- VPointSelector = (VPtPair, VPtArray); { so C++ unions can have names }
- VPoint = RECORD { VPoints are synonomous with QD Point, only
- in 32 bit space }
- CASE VPointSelector OF
- VPtPair:
- (v, h: VCoordinate);
- VPtArray:
- (vh: ARRAY [VHSelect] OF VCoordinate);
- END;
-
- VRectSelector = (VRQuad, VRPair);
- VRect = RECORD { VRects are synonomous with QD Rects, only
- in 32 bit space }
- CASE VRectSelector OF
- VRQuad:
- (top, left, bottom, right: VCoordinate);
- VRPair:
- (topLeft, botRight: VPoint);
- END;
-
- ConfigRecord = RECORD { ??? should this be PACKED ??? if so, how
- will this affect C++ users? }
- { Values from SysEnvirons (Version 1) }
- environsVersion: INTEGER;
- machineType: INTEGER;
- systemVersion: INTEGER;
- processor: INTEGER;
- hasFPU: BOOLEAN;
- hasColorQD: BOOLEAN;
- keyboardType: INTEGER;
- atDrvrVersNum: INTEGER;
- sysVRefNum: INTEGER;
- { Derived values }
- hasROM128K: BOOLEAN; { ROM 128K - OR - Better }
- hasHFS: BOOLEAN;
-
- hasHierarchicalMenus: BOOLEAN;
- hasScriptManager: BOOLEAN;
- hasStyleTextEdit: BOOLEAN;
- hasSoundManager: BOOLEAN;
- hasWaitNextEvent: BOOLEAN;
- hasSCSI: BOOLEAN;
- hasDesktopBus: BOOLEAN;
- hasAUX: BOOLEAN;
- hasTempMem: BOOLEAN; { TRUE if Multifinder™ temp memory is avail
- }
- has32BitQD: BOOLEAN; { TRUE if 32 bit Quickdraw is installed }
- END;
-
- VAR
- {$IFC qDebug}
- gPreCondition: BOOLEAN; { true to do pre-condition processing }
- gPostCondition: BOOLEAN; { true to do post-condition processing }
- {$ENDC}
-
- gApplicationRefNum: INTEGER; { RefNum of the application's res file. }
- gConfiguration: ConfigRecord; { The _actual_ environment configuration }
- gMBarHeight: INTEGER; { Height of the menu bar in pixels }
-
- gBoolString: ARRAY [BOOLEAN] OF STRING[5]; { Used to display boolean values. }
- {$Push} {$J+}
- GFIELDTOSTRRTN: ProcPtr; { Routine that converts fields to strings. }
- {$Pop}
-
- {$Push} {$J+}
- gToolBoxInitialized: BOOLEAN; { Indicates whether toolbox has been inited
- }
- gUDialogInitialized: BOOLEAN; { Indicates whether UDialog has been inited
- }
- gUGridViewInitialized: BOOLEAN; { Indicates whether UGridView has been
- inited }
- gUPrintingInitialized: BOOLEAN; { Indicates whether UPrinting has been
- inited }
- gUTEViewInitialized: BOOLEAN; { Indicates whether UTEView has been inited
- }
- gStrippedAddress: Ptr; { an address already stripped by
- StripAddress }
- {$Pop}
-
- gRGBBlack, { RGB representation for black. }
- gRGBWhite: RGBColor; { RGB representation for white. }
- gCursorRgn: RgnHandle; { the current cursor region that will be
- passed to WaitNextEvent as the sleep
- region }
- gDeadStripSuppression: BOOLEAN; { Dynamically set to false. Condition the
- execution of a New(aTFoo) to suppress the
- dead-stripping of support for a TFoo }
- gCreateWithTemplates: BOOLEAN; { Same as gDeadStripSuppression. Left in for
- compatibility (2.0) }
-
- gMATextBoxTE: TEHandle; { a working TEHandle for use exclusively by
- MATextBox. Keeps us from having to
- continually allocate and dispose a TE
- (like TextBox does) }
-
- gTEDefaultWordBreak: ProcPtr; { The default word break routine used by TE.
- NOTE that _this_ routine (alone) does not
- take parameters using the Pascal calling
- conventions as required by SetWordBreak
- (Thank you TE!) and must be set in the TE
- by munging (Rhymes with plunging) the
- wordBreak field directly. }
-
- { S T A R T U P U T I L I T I E S }
-
- PROCEDURE InitToolBox;
- { Essential toolbox and utility initialization. }
-
- PROCEDURE DefineConfiguration(VAR configuration: ConfigRecord);
- { Fills the configuration record for the host machine. }
-
- FUNCTION ValidateConfiguration(configuration: ConfigRecord): BOOLEAN;
- { FALSE if compiled configuration doesn't match runtime config }
-
- { M I S C E L L A N E O U S U T I L I T I E S }
-
- { >>> NOTE <<<
-
- Use the following accessors _wisely_ since they can play real havoc with inter-language
- portability. These routines used to begin with %_ but, that was dropped since it translates
- into the reserved __ in C++.
-
- }
-
- FUNCTION GetParmBlockPtr: LONGINT;
- INLINE $2E88; { MOVE.L A0,(A7) }
- { Formerly, %_GetA0. Return the value of register A0. Useful for getting the pointer
- to the parameter block from a VBL task or a completion routine. }
-
- FUNCTION GetA5: LONGINT;
- INLINE $2E8D; { MOVE.L A5,(A7) }
- { Formerly, %_GetA5. Return the value of register A5. Useful for getting the immediate value
- of A5 which is not always the same as CurrentA5. Generally a pointer to the program's
- global area and jump table. }
-
- FUNCTION GetCurStackFramePtr: Ptr;
- INLINE $2E8E; { MOVE.L A6,(A7) }
- { Formerly, %_GetA6. Return the value of register A6. Usually a pointer to the local stack
- frame. Most often used to find out the caller's name when invoking a debugging routine. }
-
- FUNCTION GetCurStackTop: Ptr;
- INLINE $2E8F; { MOVE.L A7,(A7) }
- { Formerly, %_GetA7. Return the value of register A7. Usually the top of stack. Useful
- for stack sniffing (not a crime). }
-
- {--------------------------------------------------------------------------------------------}
-
- PROCEDURE BlockSet(destPtr: Ptr;
- byteCount: LONGINT;
- setVal: UNIV SignedByte);
- { Sets a block of memory to a value. }
-
- PROCEDURE CenterRectOnScreen(VAR aRect: Rect;
- horizontally, vertically, forDialog: BOOLEAN);
- { Horizontally and/or vertically centers the given rectangle on the main screen. If forDialog
- is true then the rect is vertically centered closer to the top of the screen as for a modal
- dialog. }
-
- FUNCTION CompareStrings(first, second: Str255): INTEGER;
- { Returns -1, 0, or 1 if first <, =, or > second. }
-
- PROCEDURE CopyStr255(VAR fmStr: Str255;
- toAddr: UNIV Ptr);
- { Copies a string, copying ONLY what's necessary }
-
- PROCEDURE EachWMgrWindowDo(PROCEDURE DoToWMgrWindow(theWMgrWindow: WindowPtr));
- { Calls DoToWMgrWindow for each window in the windowlist starting at FrontWindow. }
-
- FUNCTION FindWindowBefore(theWindow: WindowPtr): WindowPtr;
- { returns the window just before a given window. Returns nil if the given window is frontmost
- or not found. }
-
- FUNCTION PRStr(astr: Str255): Ptr;
- INLINE $2E9F; { Move.L (A7)+,(A7) }
- { For brain-damaged compiler, which can't pass the address of a string in a packed record,
- even though it has to be byte-aligned by definition. Sure, maybe it's not word aligned, but for a
- BlockMove we don't care. When calling CopyStr255 where the destination is the address of a
- Str255 in a packed record, call it like this: CopyStr255(fromStr, PRStr(packedStr)); }
-
- FUNCTION AtStr(astr: Str255): StringPtr;
- INLINE $2E9F; { Move.L (A7)+,(A7) }
- { Lets you take the address of a string constant so you can pass pointers with no stack copy.
- Use it like this: AtStr('Foo'); }
-
- FUNCTION AtMAName(astr: MAName): MANamePtr;
- INLINE $2E9F; { Move.L (A7)+,(A7) }
- { Lets you take the address of a string constant so you can pass pointers with no stack copy.
- Use it like this: AtMAName('Bar'); }
-
- PROCEDURE PullApplicationToFront;
- { Applications don't start as the frontmost layer under MultiFinder™. They come to the front
- after a few Event calls. If you have a splash screen at startup then you probably want to
- use this call. }
-
- PROCEDURE DefaultSize(VAR theSize: INTEGER);
- { If theSize is equal to the system font size then theSize is set to zero. Otherwise it is
- left unchanged. The purpose of this routine is to convert a font size to portable form,
- where a font size of zero is the portable equivalent to the system font size. }
-
- FUNCTION DisposeIfHandle(aHandle: UNIV Handle): Handle;
- { Disposes the handle only if it is non-NIL.
- Returns NIL for convenient assignment back to the reference passed in. } { Preferred }
-
- FUNCTION DisposeIfPtr(aPtr: UNIV Ptr): Ptr;
- { Disposes the pointer only if it is non-NIL.
- Returns NIL for convenient assignment back to the reference passed in. } { Preferred }
-
- PROCEDURE DisposIfHandle(aHandle: UNIV Handle); { Left in for compatibility (2.0) }
-
- PROCEDURE DisposIfPtr(aPtr: UNIV Ptr); { Left in for compatibility (2.0) }
-
- FUNCTION EqualBlocks(first, second: UNIV Ptr;
- theSize: INTEGER): BOOLEAN;
- { Returns true if the two blocks pointed at by first and second are equal over theSize
- bytes.}
-
- PROCEDURE FieldToString(theData: Ptr;
- fieldType: INTEGER;
- VAR theString: Str255);
- { Calls the routine whose address is stored in gFieldToStrRtn. Its purpose is to take some
- data pointed to by theData, and whose type is indicated by field type, and convert that
- data into a string representation. By default, gFieldToStrRtn points to StdFieldToString. }
-
- FUNCTION GetActualJustification(justification: INTEGER): INTEGER;
- { If the justification passed in is teJustSystem then returns teJustLeft or teJustRight
- depending on the setting of the system justification. Other justifications are just passed
- through to the result. }
-
- FUNCTION GetFontNum(fontName: Str255): INTEGER;
- { Returns the font number corresponding to the given name. If fontName is equal to
- kSysFontName then zero is returned. If fontName is equal to kApplFontName then 1 is
- returned. Otherwise the Toolbox routine GetFNum is called to get the font number. }
-
- FUNCTION GetHandleBits(h: Handle): SignedByte;
- { Return the flag byte of a handle. Left in for compatibility (2.0) }
-
- {$IFC NOT qNeedsColorQD}
-
- PROCEDURE GetIfColor(VAR aColor: RGBColor);
- { If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. }
- {$ELSEC}
-
- PROCEDURE GetIfColor(VAR aColor: RGBColor);
- INLINE _GetForeColor;
- {$ENDC}
- { Fetches current foreground color. Works for both old and new QuickDraw. }
-
- {$IFC NOT qNeedsColorQD}
-
- PROCEDURE GetIfBkColor(VAR aColor: RGBColor);
- { If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. }
- {$ELSEC}
-
- PROCEDURE GetIfBkColor(VAR aColor: RGBColor);
- INLINE _GetBackColor;
- {$ENDC}
- { Fetches current background color. Works for both old and new QuickDraw. }
-
- PROCEDURE GetPortTextStyle(VAR theTextStyle: TextStyle);
- { Returns the textStyle representing the current state of thePort. }
-
- PROCEDURE GetPortFontInfo(fontNum: INTEGER;
- VAR fontName: Str255;
- VAR fontSize: INTEGER);
- { Returns the font name corresponding to a given name, in portable format. i.e. if fontNum is
- the system font then kSysFontName is returned; if fontNum is the application font then
- kApplFontName is return; otherwise the Toolbox routine GetFontName is called to get the
- font name. Then, if fontNum is the system or application font, a 0 is returned if the size
- is the default size. }
-
- FUNCTION GetTrapType(theTrap: INTEGER): TrapType;
- { Returns the trap's type (OSTrap or ToolTrap). }
-
- FUNCTION IntMultiply(x, y: INTEGER): LONGINT;
- INLINE $301F, { MOVE.W (A7)+,D0 }
- $C1DF, { MULS.W (A7)+,D0 }
- $2E80; { MOVE.L D0,(A0) }
- { Multiplies two integers and returns a longint result. Note that the Pascal compiler will
- generate a 16-bit result if you say n := x * y, truncating the upper 16-bits. Furthermore,
- if either x or y is a longint then the compiler expands both operands to 32-bits and calls
- a 32-bit multiply subroutine. IntMultiply avoids these problems. }
-
- FUNCTION IsHandle(h: UNIV Handle): BOOLEAN;
- { Returns true or false for handlehood of h }
-
- FUNCTION IsHandleLocked(h: UNIV Handle): BOOLEAN;
- { Returns lockState of h }
-
- {$IFC qDebug}
-
- FUNCTION IsHandlePurged(h: UNIV Handle): BOOLEAN;
- { Returns purgeState of h }
- {$ElseC}
-
- FUNCTION IsHandlePurged(h: UNIV Handle): BOOLEAN;
- INLINE $205F, { MOVE.L (A7)+,A0 }
- $4A90, { TST.L (A0) }
- $57D7, { SEQ (A7) }
- $4417; { NEG.B (A7) }
- { Returns purgeState of h }
- {$EndC}
-
- FUNCTION LengthRect(r: Rect;
- vhs: VHSelect): INTEGER;
- { If vhs is v, returns the length of r; else returns the width of r. }
-
- PROCEDURE LockHandleHigh(h: Handle);
- { Convenience function. Moves a handle high (MoveHHi) and locks it (HLock). The two
- operations are very frequently performed together thus, this procedure. Ignores NIL
- handles. }
-
- FUNCTION LongerSide(VAR r: Rect): VHSelect;
- { Return an indication of which side is longer. }
-
- PROCEDURE LIntToHex(decNumber: UNIV LONGINT;
- VAR hexNumber: String8;
- noOfDigits: INTEGER);
- { LIntToHex converts decNumber to a hexidecimal string of noOfDigits length. }
-
- FUNCTION MAUseResFile(refNum: INTEGER): INTEGER;
- { Like the ToolBox UseResFile but, it also returns the old CurResFile setting }
-
- PROCEDURE MATextBox(text: Ptr;
- itsLength: LONGINT;
- box: Rect;
- itsJust: INTEGER;
- autoWrap: BOOLEAN;
- wordBreak: ProcPtr;
- eraseFirst: BOOLEAN;
- spaceForCaret: BOOLEAN);
- { Like the toolbox TextBox but, it also gives you control over whether the text should
- word-wrap with autoWrap, whether the box should be erased first with eraseFirst and, if
- word-wrap is specified, where the word breaks should be with wordBreak (pass NIL to use
- the default word-wrap routine in TE. Since TextBox uses TE to image the text,
- spaceForCaret lets us adjust the drawn text by 1 pixel (the insertion caret) on the left and
- right. If the text is editable or could become editable (as in TEditText) you probably want
- to leave space for a caret. If the text is a title or something then you probably don't
- want to leave space for a caret.}
-
- PROCEDURE MADrawString(s: StringPtr; box: Rect; justification: INTEGER);
- { A convenience routine. Like the toolbox DrawString but, it uses a StringPtr to help
- reduce stack space requirements. And It also gives you control over
- the bounds into which the text will be drawn and draws it in the correct international
- direction. This routine is _MUCH_ slower than DrawString. }
-
- FUNCTION Max(a, b: LONGINT): LONGINT;
- INLINE $201F, { MOVE.L (A7)+,D0 }
- $2E9F, { MOVE.L (A7)+,(A7) }
- $B097, { CMP.L (A7),D0 }
- $6F02, { BGE.S *+4 }
- $2E80; { MOVE.L D0,(A7) }
- { Returns the maximum of a and b. }
-
- FUNCTION Min(a, b: LONGINT): LONGINT;
- INLINE $201F, { MOVE.L (A7)+,D0 }
- $2E9F, { MOVE.L (A7)+,(A7) }
- $B097, { CMP.L (A7),D0 }
- $6C02, { BLE.S *+4 }
- $2E80; { MOVE.L D0,(A7) }
- { Returns the minimum of a and b. }
-
- FUNCTION MinMax(MinVal, expression, MaxVal: LONGINT): LONGINT;
- { Returns the expression bounded by minimum and maximum }
-
- PROCEDURE NumberToHex(theNumber: UNIV LONGINT;
- VAR hexString: Str255;
- hexDigits: INTEGER);
- { Converts theNumber to a hex string preceeded with '$'.}
-
- FUNCTION PinOnRect(theRect: Rect;
- thePt: Point): LONGINT;
- { Like PinRect except that if thePt.h (or v) is >= theRect.right (bottom) it returns
- theRect.right (bottom). PinRect returns 1 less than that except if thePt is exactly on the
- edge of theRect.}
-
- FUNCTION StripLong(address: UNIV Ptr): LONGINT;
- { same function as the glue/trap stripAddress only the types are long and modified to bypass
- the inefficient MPW glue!!. If inlines could reference relocatables it could even be inline. }
-
- PROCEDURE PointerToHex(theNumber: UNIV LONGINT;
- VAR hexString: Str255;
- hexDigits: INTEGER);
- { If theNumber is zero, then hexString is set to 'Nil'. Else theNumber is converted to a hex
- string preceeded with '$'.}
-
- FUNCTION RectsNest(outer, inner: Rect): BOOLEAN;
- { Determine if inner nests within outer. }
-
- FUNCTION VRectsNest(outer, inner: VRect): BOOLEAN;
- { Determine if inner nests within outer for VCoordinates. }
-
- FUNCTION RoundUp(aNumber: LONGINT;
- aModulus: INTEGER): LONGINT;
- { Rounds aNumber up so that it is evenly divisible by aModulus. }
-
- FUNCTION SetKeyScript(newKeyScript: INTEGER): INTEGER;
- { If newKeyScript is different from the current key script, then the key script is set to
- newKeyScript. (The reason we don't want to set the key script to the same thing is that the
- Script Mgr. does a FlushEvents when it sets the key script.) }
-
- PROCEDURE SetHandleBits(h: Handle;
- theBits: SignedByte);
- { Sets the flag byte of a handle. Left in for compatibility (2.0) }
-
- {$IFC NOT qNeedsColorQD}
-
- PROCEDURE SetIfColor(aColor: RGBColor);
- { If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. }
- {$ELSEC}
-
- PROCEDURE SetIfColor(aColor: RGBColor);
- INLINE _RGBForeColor;
- {$ENDC}
- { Sets foreground color. Works for both old and new QuickDraw. }
-
- {$IFC NOT qNeedsColorQD}
-
- PROCEDURE SetIfBkColor(aColor: RGBColor);
- { If flag qNeedsColorQD is FALSE then use this method, otherwise use the one below. }
- {$ELSEC}
-
- PROCEDURE SetIfBkColor(aColor: RGBColor);
- INLINE _RGBBackColor;
- {$ENDC}
- { Sets background color. Works for both old and new QuickDraw. }
-
- PROCEDURE SetPortTextStyle(theTextStyle: TextStyle);
- { Sets the font style of the current port to the characteristics of theTextStyle. }
-
- PROCEDURE SetRGBColor(VAR RGB: RGBColor;
- red, green, blue: INTEGER);
- { Sets RGB to the given colors. }
-
- PROCEDURE SetTextStyle(VAR theTextStyle: TextStyle;
- theFont: INTEGER;
- theStyle: Style;
- theSize: INTEGER;
- theColor: RGBColor);
- { Sets theTextStyle to the given characteristics }
-
- PROCEDURE StdFieldToString(theData: Ptr;
- fieldType: INTEGER;
- VAR theString: Str255);
- { This routine converts all field types defined by the constants in this unit. }
-
- PROCEDURE ScrapStuffFields(aTitle: Str255;
- VAR aScrapStuff: ScrapStuff;
- PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- { Used to inspect the fields of a ScrapStuff. }
-
- PROCEDURE TextStyleFields(aTitle: Str255;
- VAR aStyle: TextStyle;
- PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- { Used to inspect the fields of a TextStyle record. }
-
- PROCEDURE ConfigRecFields(aTitle: Str255;
- VAR aConfigRec: ConfigRecord;
- PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- { Used to inspect the fields of a Config record. }
-
- FUNCTION TrapExists(theTrap: INTEGER): BOOLEAN;
- { Returns true if the given trap exists at run-time }
-
- FUNCTION UprChar(ch: CHAR): CHAR;
- { Returns ch converted to upper case }
-
- PROCEDURE UprStr255(VAR s: Str255);
- { Converts s to all upper case. }
-
- PROCEDURE UprMAName(VAR s: MAName);
- { Converts s to all upper case. }
-
- FUNCTION LowerChar(ch: CHAR): CHAR;
- { Returns ch converted to lower case }
-
- PROCEDURE LowerStr255(VAR s: Str255);
- { Converts s to all lower case. }
-
- PROCEDURE UseSelectionColor;
- INLINE $08B8, $0007, kLMHiliteMode; { BCLR #$07,kLMHiliteMode }
- { Call to make the next (and only the next) QD operation use the selection color. }
-
- PROCEDURE UseROMMap(resLoad: BOOLEAN);
- { Call this before any Resource Manager call for which you might like to use ROM resources.
- Remember, if you pass FALSE to this then you should call SetResLoad(TRUE) afterwards. }
-
- PROCEDURE WithApplicationResFileDo(PROCEDURE DoWithResFile);
- { Performs a proc with the application res file as the curResFile restoring the prev setting
- at completion. }
-
- { F I L E U T I L I T I E S }
-
- FUNCTION CloseFile(dataRefnum, rsrcRefnum: INTEGER): OSErr;
- { Closes the data and resource forks of a file. If dataRefnum = kNoFileRefnum then the data
- fork is not closed. Likewise, if rsrcRefnum = kNoFileRefnum then the resource fork is not
- closed. Returns noErr if successful, else an O.S. error. }
-
- FUNCTION DeleteFile(namePtr: StringPtr;
- volRefnum: INTEGER): OSErr;
- { Deletes the specified file; uses FillInDirID to bypass the Poor Man's Search Path. }
-
- FUNCTION FileModDate(name: Str255;
- volRefnum: INTEGER): LONGINT;
- { Returns file modification date or 0 if an I/O error occurs }
-
- FUNCTION FillInDirID(pb: HParmBlkPtr): OSErr;
- { Based on the ioVRefnum field of pb^, looks up the dirID of the working directory and fills
- it into the ioDirID field. If HFS is not installed, it sets the ioDirID to 0. This is used
- to inhibit the PMSP. After setting up your HParamBLockRec, call this to fill in the dirID
- and then make the H form of the call (eg., PBHGetFInfo rather than PBGetFInfo). }
-
- FUNCTION GetDirID(VAR vRefnum: INTEGER;
- VAR dirID: LONGINT): OSErr;
- { Returns the dirID corresponding to a given wdRefnum; changes vRefnum to be a real volume
- refnum. }
-
- FUNCTION GetFileInfo(name: Str255;
- volRefnum: INTEGER;
- VAR info: HParamBlockRec): OSErr;
- { Makes a PBHGetFInfo call, and returns result in info. Bypasses PMSP. }
-
- FUNCTION NumBlocks(numBytes: LONGINT;
- blkSize: LONGINT): LONGINT;
- { Returns the number of blocks required to store numBytes, given that the block size is
- blkSize. }
-
- FUNCTION MAOpenFile(name: Str255;
- volRefnum: INTEGER;
- openData, openRsrc: BOOLEAN;
- dataPerm, rsrcPerm: INTEGER;
- VAR dataRefnum, rsrcRefnum: INTEGER): OSErr;
- { Open the specified forks of the file using the specified permissions. Returns kNoFileRefnum
- for refnums that are not (or cannot) be opened. On 64K ROM machines, rsrcPerm is ignored.
- Returns an O/S error if the data fork does not exist; returns a rsrcRefnum of kNoFileRefnum
- if the resource fork does not exist. Returns an O/S error for all other errors. If no error
- occurs, returns NoErr. }
-
- { D E B U G G I N G U T I L I T I E S }
-
- FUNCTION ConcatNumber(aString: Str255;
- aNumber: LONGINT): Str255;
- { Returns aString appended with the string representation of aNumber }
-
- FUNCTION CanReadLn: BOOLEAN;
- { returns TRUE if WritelnWindow is available and the display is not suppressed }
-
- FUNCTION CanWriteLn: BOOLEAN;
- { returns TRUE if WritelnWindow is available }
-
- FUNCTION ReadInteger(prompt: Str255): INTEGER;
- { Displays prompt and reads an integer from the debug window. }
-
- FUNCTION ReadYesNo(prompt: Str255): BOOLEAN;
- { Displays prompt and accepts a 'y' or 'n' as input from the debug
- window. }
-
- FUNCTION VerboseIsHandle(h: UNIV Handle): BOOLEAN;
- { Returns true if h is really a handle. If not then it prints diagnostic info about the
- alleged handle. }
-
- PROCEDURE WritePt(pt: Point);
- { Writes the point in the debug window. }
-
- PROCEDURE WritePtr(val: UNIV LONGINT);
- { Writes the pointer, in hex, in the debug window. }
-
- PROCEDURE WriteRect(r: Rect);
- { Writes the rectangle in the debug window. }
-
- PROCEDURE WriteBoolean(b: BOOLEAN);
- { Writes the boolean in the debug window. }
-
- PROCEDURE WriteVPt(pt: VPoint);
- { Writes the VPoint in the debug window. }
-
- PROCEDURE WriteVRect(r: VRect);
- { Writes the VRect in the debug window. }
-
- PROCEDURE WrLblPt(aLabel: Str255;
- pt: Point);
- { Writes the label, ' = ', the point, to the debug window. }
-
- PROCEDURE WrLblPtr(aLabel: Str255;
- val: UNIV LONGINT);
- { Writes the label, ' = ', the pointer in hex, to the debug window. }
-
- PROCEDURE WrLblRect(aLabel: Str255;
- r: Rect);
- { Writes the label, ' = ', the rectangle, to the debug window. }
-
- PROCEDURE WrLblBoolean(aLabel: Str255;
- b: BOOLEAN);
- { Writes the label, ' = ', the boolean, to the debug window. }
-
- PROCEDURE WrLblVPt(aLabel: Str255;
- pt: VPoint);
- { Writes the label, ' = ', the VPoint in the debug window. }
-
- PROCEDURE WrLblVRect(aLabel: Str255;
- r: VRect);
- { Writes the lable, ' = ', the VRect in the debug window. }
-
- PROCEDURE WriteSig(theID: IDType);
- { Writes out an IDType signature. }
-
- PROCEDURE WrLblSig(theLabel: Str255;
- theID: IDType);
- { Writes the label, ' =', theID in the debug window. }
-
- PROCEDURE WrLblHandleContents(aLabel: Str255;
- theHandle: UNIV Handle);
- { Writes the label, ' =', theHandle in the debug window. }
-
- PROCEDURE WriteHandleContents(theHandle: UNIV Handle);
- { Writes theHandle in the debug window. }
-
- PROCEDURE WriteHexInt(theInt: INTEGER);
- { Writes theInt in the debug window. }
-
- PROCEDURE WrLblHexInt(theLabel: Str255;
- theInt: INTEGER);
- { Writes the label, ' =', theInt in the debug window. }
-
- PROCEDURE WriteHexLongint(theLongint: LONGINT);
- { Writes theLongint in the debug window. }
-
- PROCEDURE WrLblHexLongint(theLabel: Str255;
- theLongint: LONGINT);
- { Writes the label, ' =', theLongint in the debug window. }
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-